﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FunBox.ViewModels;
using BussinessObjects;

namespace FunBox.Controllers
{


    public class TeamController : Controller
    {
        TeamManager teamMgr;
        FixtureManager fixtureMgr;
        public ActionResult Index()
        {
            teamMgr = new TeamManager();
            fixtureMgr = new FixtureManager();

            var team = teamMgr.GetTeams();
            var viewModel = new TeamIndexViewModel()
            {
                Teams = team.ToList(),
                NumberOfTeams = team.Count()

            };
            var fixtures =

                fixtureMgr.GetFixtures(1);
            ViewData["Fixtures"] = fixtures.ToList();

            return View(viewModel);
        }

        /// <summary>
        ///  Get the team with ID
        /// </summary>
        /// <param name="TeamID"></param>
        /// <returns></returns>
        public ActionResult GetPlayers(string teamName)
        {
            teamMgr = new TeamManager();
            var playerData = teamMgr.GetPlayers(1, teamName);
            return View(playerData);
        }

        public ActionResult PlayerScore(int crewID, int seasonID = 1)
        {
            teamMgr = new TeamManager();
            var playerScore = teamMgr.GetPlayerScore(1, crewID);
            return View(playerScore);
        }

        public ActionResult Fixtures(string teamName, int seasonID = 1)
        {
            return View();
        }

        // GET: /Abcd/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Abcd/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult EditTeam(string teamName)
        {
            teamMgr = new TeamManager();
            var details = teamMgr.TeamsDetails(teamName);
            return View(details);
        }

        [HttpPost]
        public ActionResult EditTeam(string teamName, FormCollection formValues)
        {
            teamMgr = new TeamManager();
            DataAccess.Team team;
            team = new DataAccess.Team();
            team.TeamName = formValues.GetValue("TeamName").ToString();
            return View();
        }
    }
}
